package com.icinfo.cloud.provider.punish.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.page.PageResponse;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.HeaderUtil;
import com.icinfo.cloud.provider.exception.BusinessException;
import com.icinfo.cloud.provider.punish.approval.dto.*;
import com.icinfo.cloud.provider.punish.approval.vo.*;
import com.icinfo.cloud.provider.punish.dto.UpdateRegisterTerminalTypeDto;
import com.icinfo.cloud.provider.punish.mapper.*;
import com.icinfo.cloud.provider.punish.service.ApprovalService;
import com.icinfo.cloud.provider.punish.service.IPrintService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseBasicInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseIllegalParkingRecordVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.model.CaseCollectiveDiscuss;
import com.icinfo.cloud.provider.punish.vo.CaseInfoVo;
import com.icinfo.cloud.provider.punish.vo.RegisterTerminalTypeVo;
import com.icinfo.cloud.provider.punish.vo.UpdateRegisterTerminalTypeVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 审批相关实现
 * @author Administrator
 */
@Service
@Slf4j
public class PrintServiceImpl implements IPrintService {

    @Value("${dzh.url}")
    private String url;

    /**
     * 查询当前设备是否需已有终端类型
     * @author liyafeng
     * @date 2023/3/15
      * @param outsideUid
     * @return {@link RegisterTerminalTypeVo}
     */
    @Override
    public RegisterTerminalTypeVo getRegisterTerminalType(String outsideUid) {
        Map<String,Object> urlParam=new HashMap<>();
        urlParam.put("outsideUid",outsideUid);
        Map<String, String> headers = HeaderUtil.headerInfo();
        String response = HttpUtil.createGet(url.concat("/commandCenter/equipment/unlogin/register/getRegisterTerminalType")).addHeaders(headers).form(urlParam).execute().body();
        System.out.println("是否需已有终端类型返回：+++++++"+response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        if (jsonObject.getIntValue("code") == 200) {
            String data = jsonObject.getString("data");
            RegisterTerminalTypeVo vo=JSONObject.parseObject(data, RegisterTerminalTypeVo.class);
            return vo;
        }
        return null;
    }
    /**
     *查询当前PDA是否为黑名单，并进行更新终端设备
     * @author liyafeng
     * @date 2023/3/15
      * @param updateRegisterTerminalTypeDto
     * @return {@link UpdateRegisterTerminalTypeVo}
     */
    @Override
    public UpdateRegisterTerminalTypeVo updateRegisterTerminalType(UpdateRegisterTerminalTypeDto updateRegisterTerminalTypeDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(updateRegisterTerminalTypeDto);
        String response = HttpUtil.createPost(url.concat("/commandCenter/equipment/unlogin/register/updateRegisterTerminalType")).addHeaders(headers).body(param).execute().body();
        System.out.println("查询当前PDA是否为黑名单返回：+++++++"+response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        if (jsonObject.getIntValue("code") == 200) {
            String data = jsonObject.getString("data");
            UpdateRegisterTerminalTypeVo vo=JSONObject.parseObject(data, UpdateRegisterTerminalTypeVo.class);
            return vo;
        }
        return null;
    }

    /**
     * 获取大综合token
     * @author liyafeng
     * @date 2023/3/15
      * @param
     * @return {@link String}
     */
    @Override
    public String getDzhToken() {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String response = HttpUtil.createGet(url.concat("/taskCenter/common/getDzhToken")).addHeaders(headers).execute().body();
        System.out.println("是否需已有终端类型返回：+++++++"+response);
        JSONObject jsonObject = JSONObject.parseObject(response);
        if (jsonObject.getIntValue("code") == 200) {
            String token = jsonObject.getString("data");
            return token;
        }
        return null;
    }
}
